//
//  pickerViewController.m
//  iSeeColor
//
//  Created by Alberto Rivera on 11/2/12.
//  Copyright (c) 2012 Wyatt Gosling. All rights reserved.
//

#import "pickerViewController.h"

@interface pickerViewController ()

@end

@implementation pickerViewController
@synthesize ddlStatus;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    arrStatus = [[NSArray alloc] initWithObjects:@"Red Blindness", @"Green Blindness", nil];
    [ddlStatus reloadAllComponents];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    int row_sel = [defaults integerForKey:@"colorBlindnessType"]-1;
    [ddlStatus selectRow:row_sel inComponent:0 animated:YES];
    
}

- (void)viewDidUnload
{
    [self setDdlStatus:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    //One column
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    //set number of rows
    return arrStatus.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    //set item per row
    return [arrStatus objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	int colorBlindnessType = row + 1;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:colorBlindnessType forKey:@"colorBlindnessType"];
}


@end
